#!/bin/sh

#. /etc/rc.d/init.d/functions
#ulimit -c unlimited

echo 'config qemu network with xen bridge for ' $*

bridge=$2

#
# Old style bridge setup with netloop, used to have a bridge name
# of xenbrX, enslaving pethX and vif0.X, and then configuring
# eth0.
#
# New style bridge setup does not use netloop, so the bridge name
# is ethX and the physical device is enslaved pethX
#
# So if...
#
#   - User asks for xenbrX
#   - AND xenbrX doesn't exist
#   - AND there is a ethX device which is a bridge
#
# ..then we translate xenbrX to ethX
#
# This lets old config files work without modification
#
if [ ! -e "/sys/class/net/$bridge" ] && [ -z "${bridge##xenbr*}" ]
then
   if [ -e "/sys/class/net/eth${bridge#xenbr}/bridge" ]
   then
      bridge="eth${bridge#xenbr}"
   fi
fi

ifconfig $1 0.0.0.0 up
brctl addif $bridge $1 || true
